package routers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)
import "BeegoFirst/controllers"

func init() {

	//注册过滤器
	beego.InsertFilter("/api/*", beego.BeforeRouter, fileFunc)

	//路由：
	beego.Router("/login", &controllers.LoginController{})
	beego.Router("/register", &controllers.RegController{})
	beego.Router("/", &controllers.GotoController{})
	beego.Router("/api/index", &controllers.IndexController{})
	beego.Router("/api/add", &controllers.AddController{})
	beego.Router("/api/cot", &controllers.ContentController{})
	beego.Router("/api/del", &controllers.DelController{})
	beego.Router("/api/update", &controllers.UpDateController{})
	beego.Router("/api/addType", &controllers.TypeControllers{})
	beego.Router("/api/logout", &controllers.LogoutController{})

}

func fileFunc(ctx *context.Context) {
	userName := ctx.Input.Session("userName")
	if userName == nil {
		ctx.Redirect(302, "/login")
	}
}
